package com.example.foobar.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.foobar.business.service.ImsGhostCustomActiveRecordService;
import com.example.foobar.dao.service.ImsGhostCustomActiveRecordDaoService;
import com.example.foobar.dto.DABaseDTO;
import com.example.foobar.entity.ImsGhostCustomActiveRecord;
import com.example.foobar.param.ImsGhostCustomActiveRecordPageParam;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author 郑英奔
 * @since 2021-05-31
 */
@Slf4j
@Service
public class ImsGhostCustomActiveRecordServiceImpl implements ImsGhostCustomActiveRecordService {
    @Autowired
    private ImsGhostCustomActiveRecordDaoService imsGhostCustomActiveRecordDaoService;

    @Override
    public boolean saveImsGhostCustomActiveRecord(ImsGhostCustomActiveRecord imsGhostCustomActiveRecord) {
        return imsGhostCustomActiveRecordDaoService.saveImsGhostCustomActiveRecord(imsGhostCustomActiveRecord);
    }

    @Override
    public boolean updateImsGhostCustomActiveRecord(ImsGhostCustomActiveRecord imsGhostCustomActiveRecord) {
        return imsGhostCustomActiveRecordDaoService.updateImsGhostCustomActiveRecord(imsGhostCustomActiveRecord);
    }

    @Override
    public boolean deleteImsGhostCustomActiveRecord(Long id) {
        return imsGhostCustomActiveRecordDaoService.deleteImsGhostCustomActiveRecord(id);
    }

    @Override
    public ImsGhostCustomActiveRecord getById(Long id) {
        return imsGhostCustomActiveRecordDaoService.getById(id);
    }

    @Override
    public List<ImsGhostCustomActiveRecord> list(QueryWrapper<ImsGhostCustomActiveRecord> wrapper) {
        return imsGhostCustomActiveRecordDaoService.list(wrapper);
    }

    @Override
    public List<DABaseDTO> getActiveDataByOfficialAccountIdAndDataRange(String uniacid, Date start, Date end, List<String> messageTypeList) {
        String messageTypes = "'" + String.join("','", messageTypeList) + "'" ;
        Map<String, Object> params = new HashMap<>();
        params.put("uniacid" ,uniacid);
        params.put("startDate" ,start);
        params.put("endDate" ,end);
        params.put("messageTypes" ,messageTypes);

        return imsGhostCustomActiveRecordDaoService.getActiveDataByOfficialAccountIdAndDataRange(params);
    }

    @Override
    public List<DABaseDTO> getSubscribeCount(String uniacid, Date startDate, Date endDate) {
        Map<String, Object> params = new HashMap<>();
        params.put("uniacid", uniacid);
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        return imsGhostCustomActiveRecordDaoService.getSubscribeCount(params);
    }

    @Override
    public List<ImsGhostCustomActiveRecord> listByDate(Date date) {
        Map<String, Object> params = new HashMap<>();
        params.put("date", date);
        return imsGhostCustomActiveRecordDaoService.listByDate(params);
    }

    @Override
    public List<DABaseDTO> getActiveDataByOfficialSenceIdAndDataRange(String sceneId, Date baseDate, Date start, Date end, List<String> messageTypeList) {
        String messageTypes = "'" + String.join("','", messageTypeList) + "'" ;
        Map<String, Object> params = new HashMap<>();
        params.put("sceneId" ,sceneId);
        params.put("baseDateStart", new Date(DateUtil.getDayStartTime(baseDate).getTime()));
        params.put("baseDateEnd", new Date(DateUtil.getDayEndTime(baseDate).getTime()));
        params.put("date", baseDate);
        params.put("startDate" ,start);
        params.put("endDate" ,end);
        params.put("messageTypes" ,messageTypes);

        return imsGhostCustomActiveRecordDaoService.getActiveDataByOfficialSceneIdAndDataRange(params);
    }

    @Override
    public int getSubscribeCountBySceneId(String sceneId, Date date) {
        Map<String, Object> params = new HashMap<>();
        params.put("sceneId", sceneId);
        params.put("baseDateStart", new Date(DateUtil.getDayStartTime(date).getTime()));
        params.put("baseDateEnd", new Date(DateUtil.getDayEndTime(date).getTime()));
        return imsGhostCustomActiveRecordDaoService.getSubscribeCountBySceneId(params);
    }
}
